/*
 * Level 课时的闯关关卡
 */

import Level from 'constants/level';
import { CALL_BOOK_API } from '../middlewares';

/**
 * 创建关卡
 * @param data LevelModal
 */
export function createLevel(lessonId: number, data: Record<string, any>) {
  return {
    data,
    [CALL_BOOK_API]: {
      types: [Level.CREATE, Level.CREATE_SUCCESS, Level.CREATE_FAIL],
      uri: `/course-api/a/lessons/${lessonId}/test-levels`,
      method: 'POST',
      body: data,
    },
  };
}

/**
 * 修改关卡内容
 */
export function updateLevel(lessonId: number, levelId: number, data: Record<string, any>) {
  return {
    levelId,
    [CALL_BOOK_API]: {
      types: [Level.UPDATE, Level.UPDATE_SUCCESS, Level.UPDATE_FAIL],
      uri: `/course-api/a/lessons/${lessonId}/test-levels/${levelId}`,
      method: 'PUT',
      body: data,
    },
  };
}

/**
 * 删除关卡及测试相关数据
 * @param lessonId: 课时ID
 * @param levelId: 关卡ID
 */
export function removeLevel(lessonId: number, levelId: number) {
  return {
    levelId,
    [CALL_BOOK_API]: {
      types: [Level.REMOVE, Level.REMOVE_SUCCESS, Level.REMOVE_FAIL],
      uri: `/course-api/a/lessons/${lessonId}/test-levels/${levelId}`,
      method: 'DELETE',
    },
  };
}

/**
 * 查询Level列表
 * @param lessonId 课时ID
 */
export function fetchLevels(lessonId: number) {
  return {
    lessonId,
    [CALL_BOOK_API]: {
      types: [Level.FETCH_LIST, Level.FETCH_LIST_SUCCESS, Level.FETCH_LIST_FAIL],
      uri: `/course-api/a/lessons/${lessonId}/test-levels`,
      method: 'GET',
    },
  };
}
